﻿using System.CodeDom;

namespace DNX.IoCnoC
{
    public interface IMethodStatement
    {
        IMethodStatement AddProperty(string propertyName, ISourceParameter sourceParameter);
        IResolverBuilder AddReturnInstance();
    }

    public class MethodStatement : IMethodStatement
    {
        public CodeMemberMethod CodeMember { get; set; }

        public IResolverBuilder Builder { get; set; }

        public IMethodStatement AddProperty(string propertyName, ISourceParameter sourceParameter)
        {
            CodeMember.Statements.Add(new CodeAssignStatement(
                                          new CodeVariableReferenceExpression(string.Format("result.{0}", propertyName)),
                                          sourceParameter.Create()));
            return this;
        }
        
        public IResolverBuilder AddReturnInstance()
        {
            var returnStatement = new CodeMethodReturnStatement { Expression = new CodeVariableReferenceExpression("result") };
            CodeMember.Statements.Add(returnStatement);
            return Builder;
        }
    }
}